package com.ybzl.common.config.minio;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  mino 配置
 *  InitializingBean 和 @Bean 的时间
 */
@Configuration
public class MinioConfig {

    @Value("${minio.url}")
    private String url;

    @Value("${minio.accessKey}")
    private String accessKey;

    @Value("${minio.secretKey}")
    private String secretKey;

    @Value("${minio.bucketName}")
    private String bucketName;

    @Bean
    public MinioPool minioPool() {
        GenericObjectPoolConfig<MinioConn> config =
                new GenericObjectPoolConfig<>();
        config.setJmxEnabled(false);
        config.setMaxTotal(8); // 默认8个链接
        MinioFactory factory = new MinioFactory(url, accessKey, secretKey);
        return new MinioPool(factory, config);
    }

    public String getBucketName() {
        return bucketName;
    }
}
